package com.byx.imclientutil.netty;

import com.byx.imclientutil.listener.OnApplicationLayerCallBack;
import com.byx.imclientutil.protobuf.ChatMessageProtobuf;

/**
 * MessageDispatcher
 * 消息转发器
 * @author Superb
 * @date 2021/4/4 20:17
 */
public class MessageDispatcher {
    private OnApplicationLayerCallBack mOnApplicationLayerCallBack;

    public MessageDispatcher() {
    }

    public MessageDispatcher(OnApplicationLayerCallBack mOnApplicationLayerCallBack) {
        this.mOnApplicationLayerCallBack = mOnApplicationLayerCallBack;
    }

    public void setOnEventListener(OnApplicationLayerCallBack callBack) {
        this.mOnApplicationLayerCallBack = callBack;
    }

    /**
     * 接收消息，并通过OnEventListener转发消息到应用层
     * @param msg
     */
    public void receivedMsg(ChatMessageProtobuf.Msg msg) {
        if(mOnApplicationLayerCallBack == null) {
            return;
        }
        mOnApplicationLayerCallBack.dispatchMessage(msg);
    }
}
